// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   LineStyle.java

package com.java4less.rchart;

import com.java4less.rchart.gc.ChartColor;
import com.java4less.rchart.gc.ChartGraphics;

// Referenced classes of package com.java4less.rchart:
//			ChartLoader

public class LineStyle
{

	int lineType;
	float lWidth;
	ChartColor color;
	public float alphaValue;
	public static final int LINE_NORMAL = 1;
	public static final int LINE_DASHED = 2;
	public static final int LINE_DOTS = 3;

	public LineStyle(float w, ChartColor c, int t)
	{
		alphaValue = 1.0F;
		lineType = t;
		lWidth = w;
		color = c;
	}

	public LineStyle(float w, ChartColor c, int t, float alpha)
	{
		this(w, c, t);
		alphaValue = alpha;
	}

	public static LineStyle createFromString(String s)
	{
		String items[];
		float floa;
		int typ;
		ChartColor c;
		items = ChartLoader.convertList(s);
		if (items == null)
			return null;
		if (items.length < 3)
			return null;
		floa = 0.0F;
		try
		{
			floa = (new Float(items[0])).floatValue();
		}
		catch (Exception e)
		{
			floa = 0.2F;
		}
		typ = 1;
		if (items[2].compareTo("DASHED") == 0)
			typ = 2;
		if (items[2].compareTo("DOTS") == 0)
			typ = 3;
		c = ChartLoader.convertColor(items[1]);
		if (items.length <= 3)
			return new LineStyle(floa, c, typ);
		return new LineStyle(floa, c, typ, (new Float(items[3])).floatValue());
		Exception e;
		e;
		return null;
	}

	public void setType(int t)
	{
		lineType = t;
	}

	public int getType()
	{
		return lineType;
	}

	public ChartColor getColor()
	{
		return color;
	}

	public void setColor(ChartColor c)
	{
		color = c;
	}

	public float getWidth()
	{
		return lWidth;
	}

	public void setWidth(float f)
	{
		lWidth = f;
	}

	public void drawArc(ChartGraphics g, int x, int y, int w, int h, int a1, int a2)
	{
		setGraphicsProperties(g);
		g.drawArc(x, y, w, h, a1, a2);
	}

	public void drawPolygon(ChartGraphics g, int x[], int y[], int c)
	{
		for (int i = 1; i < c; i++)
			draw(g, x[i - 1], y[i - 1], x[i], y[i]);

		draw(g, x[0], y[0], x[c - 1], y[c - 1]);
	}

	public void drawOpenPolygon(ChartGraphics g, int x[], int y[], int c)
	{
		for (int i = 1; i < c; i++)
			draw(g, x[i - 1], y[i - 1], x[i], y[i]);

	}

	public void drawRoundRect(ChartGraphics g, int x1, int y1, int x2, int y2)
	{
		int iX = x1;
		int iY = y1;
		int w = x2 - x1;
		int h = y2 - y1;
		if (w < 0)
		{
			w *= -1;
			iX = x2;
		}
		if (h < 0)
		{
			h *= -1;
			iY = y2;
		}
		setGraphicsProperties(g);
		g.drawRoundedRect(iX, iY, w, h);
	}

	public void drawRect(ChartGraphics g, int x1, int y1, int x2, int y2)
	{
		int iX = x1;
		int iY = y1;
		int w = x2 - x1;
		int h = y2 - y1;
		if (w < 0)
		{
			w *= -1;
			iX = x2;
		}
		if (h < 0)
		{
			h *= -1;
			iY = y2;
		}
		setGraphicsProperties(g);
		g.drawRect(iX, iY, w, h);
	}

	public void draw(ChartGraphics g, int x1, int y1, int x2, int y2)
	{
		setGraphicsProperties(g);
		g.drawLineWithStyle(x1, y1, x2, y2);
	}

	protected void setGraphicsProperties(ChartGraphics g)
	{
		g.setColor(color);
		int tmp = (int)lWidth;
		if (tmp == 0 && lWidth > 0.0F)
			tmp = 1;
		g.setLineWidth(tmp);
		g.setLineStyle(ChartGraphics.STROKE_NORMAL);
		if (lineType == 2)
			g.setLineStyle(ChartGraphics.STROKE_DASHED);
		if (lineType == 3)
			g.setLineStyle(ChartGraphics.STROKE_DOTTED);
	}
}
